<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:import url="/WEB-INF/jsp/header.jsp">
	<c:param name="title" value="accueil"/>
</c:import>
<script type="text/javascript">
    
    var IDENT_MODE_ON = false;
    
    var tableau_ident = new Array();
    
    $(document).ready(function(){
        $(".identification-box").change(function(e){
            fnAddIdentification($(this).val(),$("option:selected",this).text());
            IDENT_MODE_ON = false;
            $(".identification-box").hide();
        })
        $("#inputMessage").keypress(function(e){
            if(IDENT_MODE_ON){
                IDENT_MODE_ON = false;
                $(".identification-box").hide();
            } else {
                var c = String.fromCharCode(e.which);
                if(c == "@"){
                    IDENT_MODE_ON = true;
                    $(".identification-box").show();
                }
            }
        })
    })
    
    var fnAddIdentification = function(id,nom){
        $("#inputMessage").val($("#inputMessage").val() + nom);
        //tableau_ident.push(id);
        $("#inputMessage").after('<input type="hidden" name="identifications" value="'+id+'"/>');
        $("#inputMessage").focus();
    }
</script>

<div class="row-fluid">
    <div class="span8">  
        <div class="navbar">
            <div class="navbar-inner">
              <a class="brand" href="index.htm">Carnet d'Amis !</a>
              <ul class="nav">
                <li class="active"><a href="index.htm">Mon Mur</a></li>
                <li><a href="amis.htm">Mes amis</a></li>
                <li><a href="modifier.htm">Mon profil</a></li>
              </ul>
              <ul class="nav pull-right">
                <li><a href="logout.htm">Déconnexion (${user.pseudo})</a></li>
              </ul>
            </div>
        </div>
            <div class="bloc activites">
                <div class="bloc-header">
                    <div class="bloc-header-inner">
                        <h1>Activité récente</h1>
                    </div>
                </div>
                <div class="bloc-corps">
                    <div class="bloc-inner">
                        

                        <c:forEach items="${mur}" var="partage">
                            <div class="media">
                                <c:if test="${user.id == partage.auteur.id}">
                                    <a href="supprimer_partage.htm?id=${partage.id}" class="remove-partage btn btn-mini btn-warning">
                                        <i class="icon icon-remove icon-white"></i> supprimer la publication
                                    </a>
                                </c:if>
                              <a class="pull-left" href="#">
                                <img class="media-object avatar" src="${partage.auteur.avatar}">
                              </a>
                              <div class="media-body">
                                <h4 class="media-heading"><a href="profil.htm?id=${partage.auteur.id}">${partage.auteur.pseudo}</a></h4>
                                <p>${partage.message}</p>
                                <c:if test="${partage.getClass().name == 'sn.metier.Fichier'}">
                                    <c:if test="${partage.type.substring(0,5) == 'image'}">
                                    <div class="media-image row-fluid">
                                        <img src="download.htm?id=${partage.id}" class="img-polaroid"/>
                                    </div>
                                    </c:if>
                                    <c:if test="${partage.type.substring(0,5) != 'image'}">
                                    <div class="media-image row-fluid">
                                        <a href="download.htm?id=${partage.id}">
                                            <img src="http://www.stdicon.com/${partage.type}?size=64"/>
                                            Télécharger la pièce jointe en cliquant ici
                                        </a>
                                    </div>
                                    </c:if>
                                    
                                </c:if>
                              </div>
                            </div>
                        </c:forEach>
                        
                        <div style="clear:both"></div>
                    </div>
                </div>
                <div class="bloc-footer">    
                    <div class="bloc-footer-inner">

                    </div>
                </div>
            </div>
    </div>
    <div class="span4">
            <div class="bloc login-bloc">
                <div class="bloc-header">
                    <div class="bloc-header-inner">
                        <h1>Partager avec vos amis !</h1>
                    </div>
                </div>
                <div class="bloc-corps">
                    <div class="bloc-inner">

                        <form action="partage.htm" method="POST" enctype="multipart/form-data" class="form-vertical">
                              <div class="control-group">
                                <label class="control-label" for="inputMessage">Votre Message</label>
                                <div class="controls">
                                    <textarea name="message" id="inputMessage"></textarea>
                                    
                                    <select class="hide identification-box" multiple="yes">
                                        <c:forEach items="${amis}" var="am">
                                            <option value="${am.id}">${am.pseudo}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label" for="inputFichier">Votre Fichier</label>
                                <div class="controls">
                                    <input type="file" name="fichier" id="inputFichier"/>
                                    <span class="help-block">(facultatif)</span>
                                </div>
                              </div>
                              <div class="control-group">
                                <label class="control-label" for="inputDestinataire">Destinataires</label>
                                <div class="controls">
                                    <select name="destinataires" multiple="yes" id="inputDestinataire">
                                        <option value="${user.id}">Public</option>
                                        <c:forEach items="${amis}" var="am">
                                            <option value="${am.id}">${am.pseudo}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                              </div>
                              <div class="control-group">
                                <div class="controls">
                                  <button type="submit" class="btn btn-primary">Partager !</button>
                                </div>
                              </div>
                        </form>
                    </div>
                </div>
                <div class="bloc-footer">    
                    <div class="bloc-footer-inner">

                    </div>
                </div>
            </div>
            <div class="bloc login-bloc">
                <div class="bloc-header">
                    <div class="bloc-header-inner">
                        <h1>Notifications récentes</h1>
                    </div>
                </div>
                <div class="bloc-corps">
                    <div class="bloc-inner">
                        <c:forEach items="${notifs}" var="noti">
                            <div class="media">
                              <a class="pull-left" href="#">
                                <img class="media-object avatar" src="${noti.auteur.avatar}">
                              </a>
                              <div class="media-body">
                                  <c:if test="${noti.getClass().name == 'sn.metier.Amitie'}">
                                    <h4 class="media-heading">Demande d'amitié</h4>
                                    <p><a href="profil.htm?id=${noti.auteur.id}">${noti.auteur.pseudo}</a> aimerait être votre ami:<br/>
                                        "${noti.message}"<br/>
                                        <a href="accepter_ami.htm?id=${noti.id}" class="btn btn-mini btn-primary">accepter</a>
                                        <a href="refuser_ami.htm?id=${noti.id}"  class="btn btn-mini btn-warning">refuser</a>
                                    </p>
                                  </c:if>    
                                  <c:if test="${noti.getClass().name == 'sn.metier.Identification'}">
                                    <h4 class="media-heading">Identification</h4>
                                    <p>${noti.auteur.pseudo} parle de vous:<br/>
                                        <c:if test="${noti.lien.message != null}">
                                        "${noti.lien.message}"
                                    </p>
                                        </c:if>
                                        <c:if test="${noti.getClass().name == 'sn.metier.Fichier' && noti.lien.type.substring(0,5) == 'image'}">
                                     
                                    </p>   <div class="media-image row-fluid">
                                            <img src="download.htm?id=${partage.id}" class="img-polaroid"/>
                                        </div>
                                        </c:if>
                                        <a href="marquer_lu.htm?id=${noti.id}" class="btn btn-mini btn-primary">marquer comme lu</a>
                                  </c:if>    
                              </div>
                            </div>
                        </c:forEach>
                    </div>
                </div>
                <div class="bloc-footer">    
                    <div class="bloc-footer-inner">

                    </div>
                </div>
            </div>
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>